package org.collector.baseoper;

import java.util.HashMap;

import org.apache.http.client.HttpClient;
import org.collector.util.HttpClientTools;

public class ClientsWithStatuHelper {
	private HashMap<HttpClient,HttpClientStatu> clientWithStatu;
	private HashMap<String,ParamListIndex> dataSnapMap;
	public ClientsWithStatuHelper(ClientsWithStatu clientsWithStatu){
		this.clientWithStatu = clientsWithStatu.getClientWithStatu();
		this.dataSnapMap = new HashMap<String,ParamListIndex>();
	}
	
	public HttpClient allocTaskHelper(final String url){
		//new comment
		String targetUrl = HttpClientTools.determineTarget(url);
		ParamListIndex index = null;
		synchronized(dataSnapMap){
			index = dataSnapMap.get(targetUrl);
			if(index == null){
				index = new ParamListIndex(targetUrl,clientWithStatu);
				dataSnapMap.put(targetUrl, index);
			}
		}
		return index.getHttpClient();
//		Vector<HttpClient> vct_clients = new Vector<HttpClient>(clientWithStatu.keySet());
//		return vct_clients.elementAt(new Random(System.currentTimeMillis()).nextInt(vct_clients.size()));
	}
}
